import QtQuick 1.0
import Lab03 1.0
import "js/TreeUtil.js" as TreeUtil

Rectangle {
    id: node
    color: "red"
    radius: 5

    property alias root: rootPoint
    property alias link: rootLink
    property int itemCount: 4
    property int itemWidth: 20

    ConnectionPoint {
        objectName: node.objectName + "_root"
        id: rootPoint
        anchors.horizontalCenter: node.horizontalCenter
        y: 0
    }

    Link {
        id: rootLink
        smooth: true
        color: "orange"
        lineWidth: 1
        z: 3
    }

    Behavior on x { NumberAnimation { duration: 1000; } }
    Behavior on y { NumberAnimation { duration: 1000; } }

    MouseArea {
        anchors.fill: parent
        drag.target: node
        drag.axis: Drag.XandYAxis
        drag.minimumX: 0
        drag.maximumX: node.parent.width - node.width
        drag.minimumY: 0
        drag.maximumY: node.parent.height - node.height

        onClicked: console.log("[Node.qml] " + node.objectName + " clicked link: " + link.objectName);
    }

    function setFather(father, pointnum)
    {
        TreeUtil.linkNodes(father, node, pointnum);
        if ( father === null )
            console.log("[Node.qml] father === null");
    }

    function disconnectFather()
    {
        link.a = null;
    }

}
